package com.cetc.displayset;

import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

/**
 * Created by Administrator on 2016/7/15.
 */
public abstract class BaseToolbarActivity extends AppCompatActivity {

    protected abstract Fragment createFragment();
    protected abstract void setToolbar(Toolbar toolBar);

    protected void globalSet() {
        //TODO: READ PREFERENCE AND DO SOME ACTION
    }
    private void baseInitToolbar() {
        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        setToolbar(toolbar); //caller set the toolbar
        setSupportActionBar(toolbar);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_toolbar);
        baseInitToolbar();
        FragmentManager fm = getFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);
        if (fragment == null) {
            fragment = createFragment();
            fm.beginTransaction()
                    .add(R.id.fragmentContainer, fragment)
                    .commit();
        }
    }
}
